import { httpClient } from '@/utils/http/axios';
import { ErrorMessageMode } from '#/axios';
import { AjaxResult } from '@/api/model';
import { PrintReportRequestDto } from './model/print';
import { PrintUserDtoSimple, PrintTemplateUserDtoSimple } from './admin/print/model';

/** 报表模块打印URL枚举 */
enum Api {
  /** 根据打印编号获取打印模板集合 */
  GetPrintTemplatesById = '/api/rpt/getPrintTemplatesById',
  /** 根据打印编码获取打印模板集合 */
  GetPrintTemplatesByCode = '/api/rpt/getPrintTemplatesByCode',
  /** 取消默认打印 */
  CancelDefaultPrints = '/api/rpt/cancelDefaultPrints',
  /** 设置默认打印 */
  SetDefaultPrints = '/api/rpt/setDefaultPrints',
  /** 获取打印报告文件 */
  GetPrintReportFile = '/api/rpt/getPrintReportFile',
  /** 获取打印报告Base64编码 */
  GetPrintReportBase64 = '/api/rpt/getPrintReportBase64',
}

//#region 根据打印编号获取打印模板集合
/**
 * 根据打印编号获取打印模板集合
 * @param printId 打印编号
 * @param mode 错误消息模型
 */
export function getPrintTemplatesById(
  printId: string | bigint,
  mode: ErrorMessageMode = 'message',
) {
  return httpClient.get<AjaxResult>(
    {
      url: Api.GetPrintTemplatesById,
      params: { printId: printId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 根据打印编码获取打印模板集合
/**
 * 根据打印编码获取打印模板集合
 * @param printCode 打印编码
 * @param mode 错误消息模型
 */
export function getPrintTemplatesByCode(printCode: string, mode: ErrorMessageMode = 'message') {
  return httpClient.get<AjaxResult>(
    {
      url: Api.GetPrintTemplatesByCode,
      params: { printCode: printCode },
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion

//#region 取消默认打印
/**
 * 取消默认打印
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function cancelDefaultPrints(
  dtos: PrintUserDtoSimple[],
  mode: ErrorMessageMode = 'message',
) {
  return httpClient.post<AjaxResult>(
    {
      url: Api.CancelDefaultPrints,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 设置默认打印
/**
 * 设置默认打印
 * @param dtos 输入DTO
 * @param mode 错误消息模型
 */
export function setDefaultPrints(
  dtos: PrintTemplateUserDtoSimple[],
  mode: ErrorMessageMode = 'message',
) {
  return httpClient.post<AjaxResult>(
    {
      url: Api.SetDefaultPrints,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion

//#region 获取打印报告文件
/**
 * 获取打印报告文件
 * @param dto 请求DTO
 * @param mode 错误消息模型
 */
export function getPrintReportFile(dto: PrintReportRequestDto, mode: ErrorMessageMode = 'message') {
  return httpClient.post(
    {
      url: Api.GetPrintReportFile,
      params: dto,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
//#region 获取打印报告Base64编码
/**
 * 获取打印报告Base64编码
 * @param dto 请求DTO
 * @param mode 错误消息模型
 */
export function getPrintReportBase64(
  dto: PrintReportRequestDto,
  mode: ErrorMessageMode = 'message',
) {
  return httpClient.post<AjaxResult>(
    {
      url: Api.GetPrintReportBase64,
      params: dto,
    },
    {
      errorMessageMode: mode,
    },
  );
}
//#endregion
